<template>
    <div>
        用户名:
        <input type="text" name="username" v-model="username">
        <br> 密码:
        <input type="text" name="password" v-model="password">
        <br>
        <button @click="login">登录</button>
    </div>
</template>
<script>
export default {
    data() {
        return {
            username: '',
            password: ''
        }
    }, methods: {
        login() {
            //获取用户名和密码
            //发起请求登录
            this.$http.post('http://192.168.114.74/login', {
                    username: this.username,
                    password: this.password
                }, {
                    emulateJSON: true
                })
                .then(res => {
                    let code = res.body.code;
                    if (code == '002') { // 用户名不是123或者密码不是123
                        return alert('想骗我？')
                    }
                    //否则就是成功,需要让url不是通过用户的点击而改变
                    this.$router.push({
                        name: 'chatroom'
                    });
                }, res => {
                    console.log('失败');
                });
        }
    }
}
</script>
<style>
</style>
